home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / shell / dbGoodies.lha / goodies / guardfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-15  |  1.8 KB  |  88 lines

  1. /*
  2. **  guardfile.c by Daniel Balster
  3. **
  4. **  guardfile is a file guardian, which once launched watches all file access and
  5. **  helps you to debug illegal accesses.
  6. **
  7. **  usage: guardfile <filename> [<filename> ... ]
  8. **
  9. **
  10. **
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15. #include <dos/dos.h>
  16. #include <dos/notify.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/dos_protos.h>
  19.  
  20. UBYTE *V[] = "$VER: guardfile v1.0\0";
  21.  
  22. VOID _main( VOID )
  23. {
  24.     struct Library *DOSBase;
  25.     ULONG  args[4] = {0,0,0,0};
  26.  
  27.     if( DOSBase = OpenLibrary( "dos.library", 37L ) )
  28.     {
  29.     struct Process *process = FindTask( 0 );
  30.  
  31.     if( process->pr_CLI )
  32.     {
  33.         struct RDArgs *rdargs;
  34.  
  35.         if( rdargs = ReadArgs( "NAME", args, NULL ) )
  36.         {
  37.         if( args[0] )
  38.         {
  39.             struct NotifyRequest *nr;
  40.  
  41.             if( nr = (struct NotifyRequest *) AllocVec( sizeof(struct NotifyRequest), MEMF_PUBLIC|MEMF_CLEAR ) )
  42.             {
  43.             ULONG signals, signal;
  44.  
  45.             if( signal = AllocSignal( -1 ) )
  46.             {
  47.                 nr->nr_Name             =   (STRPTR) args[0];
  48.                 nr->nr_Flags            =   NRF_SEND_SIGNAL;
  49.                 nr->nr_stuff.nr_Signal.nr_Task    =   FindTask( NULL );
  50.                 nr->nr_stuff.nr_Signal.nr_SignalNum =   signal;
  51.  
  52.                 StartNotify( nr );
  53.  
  54.                 signals = Wait( (1L<<signal) | SIGBREAKF_CTRL_C );
  55.  
  56.                 if( signals & SIGBREAKF_CTRL_C )
  57.                 PutStr( "CTRL-C\n" );
  58.  
  59.                 if( signals & signal )
  60.                 PutStr( "ACCESS\n" );
  61.  
  62.                 EndNotify( nr );
  63.                 FreeSignal( signal );
  64.             }
  65.             FreeVec( nr );
  66.             }
  67.             else PrintFault( ERROR_NO_FREE_STORE, 0 );
  68.         }
  69.         else PrintFault( ERROR_REQUIRED_ARG_MISSING, 0 );
  70.  
  71.         FreeArgs( rdargs );
  72.         }
  73.         else PrintFault( IoErr(), NULL );
  74.     }
  75.     else
  76.     {
  77.         /*    workbench stuff.
  78.         do not add an icon, it should only be used by shell */
  79.  
  80.         WaitPort( &process->pr_MsgPort );
  81.         ReplyMsg( GetMsg( &process->pr_MsgPort ) );
  82.     }
  83.  
  84.     CloseLibrary( DOSBase );
  85.     }
  86. }
  87.  
  88.